/**
 * @filename:${entityName}ServiceImpl ${createTime}
 * @project ${project}  ${version}
 */
package ${serviceImplUrl};

import com.starhub.engine.generator.genid.IdGenerator;
import ${entityUrl}.${entityName};
import ${daoUrl}.${entityName}Dao;
import ${serviceUrl}.${entityName}Service;
import com.starhub.utils.Util;
import com.starhub.engine.security.utils.SecurityUtils;
import com.starhub.engine.sys.user.bean.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.*;
import java.util.stream.Collectors;

/**   
 * @Description:(${entityComment}服务实现)
 *
 * @version: ${version}
 * @author: ${author}
 * 
 */
@Service
public class ${entityName}ServiceImpl implements ${entityName}Service {

    @Autowired
    private ${entityName}Dao ${entityNameLower}Dao;

    /**
    * 新增
    * @param user
    * @param ${entityNameLower}
    * @return
    */
    public Long add(LoginUser user, ${entityName} ${entityNameLower}){

        Long id = IdGenerator.generateId();

        //数据封装，默认值添加
        ${entityNameLower}.setId(id);
        ${entityNameLower}.setCreateTime(new Date());
        ${entityNameLower}.setUpdateTime(new Date());
        ${entityNameLower}.setDeleteType(0);

        ${entityNameLower}Dao.insertSelective(${entityNameLower});
        return id;
    }

    /**
    * 更新
    * @param user
    * @param ${entityNameLower}
    * @return
    */
    public ${entityName} update(LoginUser user, ${entityName} ${entityNameLower}){
        ${entityNameLower}.setUpdateTime(new Date());
        //不允许更新的属性设置为null
        ${entityNameLower}Dao.updateByPrimaryKeySelective(${entityNameLower});
        return ${entityNameLower};
    }

    /**
    * 基本信息获取
    * @param user
    * @param id
    * @return
    */
    public ${entityName} getInfo(LoginUser user, Long id){

        ${entityName} ${entityNameLower} = ${entityNameLower}Dao.selectByPrimaryKey(id);
        return ${entityNameLower};
    }

    /**
    * (批量)删除，同时支持单条或者批量,此方法为逻辑删除
    * @param user
    * @param ids
    */
    public void deleteByType(LoginUser user, String ids,int deleteType){

        //数组转换
        List<Long> idList = Arrays.stream(ids.split(","))
            .map((id) -> Long.parseLong(id))
            .collect(Collectors.toList());
            //删除状态，目前只有1的逻辑
        ${entityNameLower}Dao.delete${entityName}ByType(idList, deleteType);
    }

    /**
    * 根据id删除，此方法为真实删除
    * @param user
    * @param ids
    */
    public void deleteRecord(LoginUser user, String ids){

        //数组转换
        List<Long> idList = Arrays.stream(ids.split(","))
            .map((id) -> Long.parseLong(id))
            .collect(Collectors.toList());
        ${entityNameLower}Dao.delete${entityName}Record(idList);
    }

    /**
    * 列表查询
    * @param user
    * @param params
    */
    public List<${entityName}> getList(LoginUser user,  Map<String , Object>  params){

        List<${entityName}> ${entityNameLower}List =  new ArrayList<${entityName}>();
            //TODO
        int pageSize = 10;
        int current = 1;
        ${entityName} record = new ${entityName}();
        record.setDeleteType(0);
        ${entityNameLower}List = ${entityNameLower}Dao.selectByPrimaryKeySelective(record);
        return ${entityNameLower}List;
    }


}